/*
 * Copyright 2010 Mark Eschbach.
 *
 * $HeadURL$
 * $Id$
 */
package com.meschbach.cise.util;

import java.io.IOException;
import java.util.Iterator;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;

/**
 *
 * @author "Mark Eschbach" &lt;meschbach@gmail.com&gt;
 */
public class JarEntryIterator implements Iterator<JarEntry> {

    JarInputStream in;
    JarEntry entry;
    boolean hasMore  = true;

    public JarEntryIterator(JarInputStream in) {
        this.in = in;
        this.entry = null;
    }

    public boolean hasNext() {
        if (entry == null && hasMore) {
            try {
                entry = in.getNextJarEntry();
                if(entry == null){
                    hasMore = false;
                }
            } catch (IOException ioe) {
                throw new RuntimeException(ioe);
            }
        }
        return entry != null;
    }

    public JarEntry next() {
        final JarEntry result = entry;
        entry = null;
        return result;
    }

    public void remove() {
        throw new UnsupportedOperationException("Not supported.");
    }
}
